package org.ls.petclinic.web;

import cn.hutool.core.util.ObjectUtil;
import org.ls.petclinic.dao.OwnerDao;
import org.ls.petclinic.dao.PetsDao;
import org.ls.petclinic.dao.VisitsDao;
import org.ls.petclinic.dao.impl.OwnerDaoImpl;
import org.ls.petclinic.dao.impl.PetsDaoImpl;
import org.ls.petclinic.dao.impl.VisitsDaoImpl;
import org.ls.petclinic.pojo.Owner;
import org.ls.petclinic.pojo.Pets;
import org.ls.petclinic.pojo.Visits;
import org.ls.petclinic.untils.JdbcUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 浪矢先生
 * @description
 * @create 2022-12-05 23:47
 */
@WebServlet(urlPatterns = "/addVisit")
public class AddVisit extends BaseServlet{
    private VisitsDao visitsDao= new VisitsDaoImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        //请求参数
        long pid = Long.parseLong(req.getParameter("pid"));
        String visitDate = req.getParameter("visitDate");
        String description = req.getParameter("description");
        int result = visitsDao.add(new Visits(null, pid, visitDate, description));
        JdbcUtils.commitAndClose();
        if (result>0){
            req.setAttribute("msg", "添加成功!");
        }else {
            req.setAttribute("msg", "添加失败!");
        }
        //页面转发
        req.getRequestDispatcher("/jsp/getPets.jsp").forward(req, resp);
//        resp.sendRedirect(req.getContextPath() + "/jsp/getUnHealthyPet.jsp");
    }
}
